package com.wsq.retrofitdemo.model.request;

import com.wsq.retrofitdemo.model.bean.Task;
import com.wsq.retrofitdemo.utils.Constants;
import com.wsq.retrofitdemo.utils.GenerateSign;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 开始进行音库训练
 * Date:2021/9/3
 * Time:10:43
 * author:wushengqi
 *
 * task Task[] 1-32 是 训练任务
 * name String 1-32 是 音库名称
 * sex Integer 否 性别 1：男 2：女
 * image String 否 图片数据的
 * base64 编码，建议 图 片 为 正 方形，且数据不要超过 500k
 * third_user_id String 1-32 是 用户 ID
 */
public class IFlyTaskStartReq extends IFlyBase{
     public List<Task> task;
     public String name;
     public int sex;
     public String image;
     public String third_user_id;

    @Override
    public String sign() {
        Map<String, String> map = new HashMap<>();
        map.put("task",taskJoint());
        map.put("image",image);
        map.put("name",name);
        map.put("sex",sex+"");
        map.put("third_user_id",third_user_id);

        map.put("clientType",clientType+"");
        try {
            return sign = GenerateSign.generateSign(openid, Constants.OPEN_KEY, "", map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    @Override
    public Map<String, String> getMap() {
        Map<String, String> map = new HashMap<>();
        map.put("task",taskJoint());
        map.put("image",image);
        map.put("name",name);
        map.put("sex",sex+"");
        map.put("third_user_id",third_user_id);

        map.put("clientType",clientType+"");
        map.put("sign",sign);
        map.put("openid",openid);
        return map;
    }

    private String taskJoint(){
        if (task != null && task.size() > 0){
            StringBuffer stringBuffer = new StringBuffer();
            for (int i = 0; i < task.size(); i++){
                if (i != task.size() - 1){
                    stringBuffer.append(task.get(i).task_id).append(task.get(i).task_type).append(";");
                }else{
                    stringBuffer.append(task.get(i).task_id).append(task.get(i).task_type);
                }

            }
        }

        return "";
    }
}
